package com.itheima.dubbo.mongodb.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.commons.pojo.mongo.LogPeach;
import com.itheima.dubbo.interfaces.LogPeachApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class LogPeachApiImpl implements LogPeachApi {
    @Autowired
    MongoTemplate mongoTemplate;
    @Override
    public void addlog(LogPeach logPeach) {
        mongoTemplate.save(logPeach);
    }

    @Override
    public List<LogPeach> findAllById(Long userId) {
        return mongoTemplate.find(Query.query(Criteria.where("userId").is(userId)), LogPeach.class);

    }
}
